﻿using System;
using System.Xml.Serialization;
using System.Web.Script.Serialization;

using Fuse8.DomainFramework.Domain;
using Fuse8.DomainFramework.BusinessService;
using Fuse8.DomainFramework.CacheService;

namespace Fuse8.ContentManagementFramework.Domain
{
    [Serializable]
    public partial class CmsTemplateRegion : Int32EntityObject
    {
        #region Linked field

        private CmsTemplate _template;

        #endregion

        #region Properties

        public virtual int TemplateId { get; set; }

        public virtual string TemplateRegionName { get; set; }

        #endregion

        #region Linked property

        [XmlIgnore]
        [ScriptIgnore]
        public CmsTemplate Template
        {
            get
            {
                if (_template == null)
                {
                    if (TemplateId != 0)
                    {
                        var businessFacade = new BusinessServiceFacade<CmsTemplate, int>();
                        if (businessFacade != null)
                        {
                            _template = businessFacade.FindOne(TemplateId);
                        }
                    }
                }

                return _template;
            }
            set
            {
                TemplateId = value != null ? value.Id : 0;

                _template = value;
            }
        }

        #endregion

        #region Constructor

        public CmsTemplateRegion()
        { }

        #endregion

        #region EntityObject override

        public override string TypeParameter
        {
            get
            {
                return "TemplateRegion";
            }
        }

        #endregion
    }
}
